@extends('layouts.layouts')
@section('title')
    <title>后台首页</title>
@endsection
@section('content')
    <link rel="stylesheet" href="/lib/layer/theme/default/layer.css"/>
    <script type="text/javascript" src="/lib/layer/layer.js"></script>
    <div class="content">
        <div class="header">
            <ul class="breadcrumb">
                <li><a href="/admin/share">裂变者</a></li>
                <li class="active">裂变者列表</li>
            </ul>
        </div>
        <div class="main-content">
            <div class="btn-toolbar list-toolbar">
                <form class="form-inline col-sm-4" action="" method="get">
                   {{--<!-- <a href="/activity/add"><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" ><i class="fa fa-plus"></i> 新增</button></a>-->--}}
                    <div class="form-group">
                        <input type="text" class="form-control" name="user_id" placeholder="用户id" value="">
                    </div>
                    <button type="submit" class="btn btn-default">筛选</button>
                </form>
                <ul class="nav nav-pills">
                    <li role="presentation" class="{{$is_fission==1?'':'active'}} commonCourse"><a href="/admin/share?is_fission=2">新媒体人</a></li>
                    <li role="presentation" class="{{$is_fission==1?'active':''}}"><a class="liveCourse" href="/admin/share??is_fission=1">咨询老师</a></li>
                </ul>
            </div>
            <div class="row">
                <div class="col-sm-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading no-collapse">裂变者列表共({{$count}})人</div>
                        <table class="table table-bordered table-striped">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>姓名</th>
                                <th>电话</th>
                                <th>备注</th>
                                <th>开始时间</th>
                                <th>操作</th>

                            </tr>
                            </thead>
                            <tbody>
                            @if($data[0])
                                @foreach($data as $v)
                                    <tr>
                                        <td>{{$v->users->id}}</td>
                                        <td>{{$v->users->nickname ? $v->users->nickname : $v->users->name}}</td>
                                        <td>{{$v->users->mobile}}</td>
                                        <td>{{$v->remark}}</td>
                                        <td>{{$v->users->created_at}}</td>
                                        <td>
                                            <a href = "/admin/shareDetail/{{$v->users->id}}?is_fission={{$is_fission}}">查看详情</a>
                                            | <a href="/admin/fission/{{$v->users->id}}/0">取消</a>|
                                             <a data-toggle="modal" onclick="transferUser(this)" data-id="{{$v->users->id}}">移交</a>
                                        </td>
                                    </tr>
                                @endforeach
                            @else
                                <tr><td colspan = "5" style="text-align:center;">暂无信息</td></tr>
                             @endif

                            </tbody>
                        </table>

                    </div>

                </div>
            </div>
            {{ $data->links() }}
        </div>
    </div>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">Modal title</h4>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group">
                            <label for="recipient-name" class="control-label">移交人:</label>
                            <input type="text" class="form-control" name="mobile" id="userMobile">
                            <input type="hidden" name="user_id" value="" />
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" onclick="userCommit();" class="btn btn-primary">确认</button>
                </div>
            </div>
        </div>
    </div>
    <script>
        function transferUser(obj) {
            var user_id = $(obj).attr('data-id');
            $("input[name='user_id']").val(user_id);
            $('#myModal').modal('show');
        }
        function userCommit(){
            var user_id = $("input[name='user_id']").val();
            var mobile = $('#userMobile').val();
            var token = '{{csrf_token()}}';
            var data = {mobile:mobile};
            var data1 = {mobile:mobile,user_id:user_id,_token:token};
            $.ajax({
                url:'/user/info',
                data:data,
                type:'GET',
                dataType:'json',
                success:function(res){
                    if(res.code == 0){
                        var notice = '移交人给：'+res.data.name+'？';
                        layer.confirm(notice, {
                            btn: ['是', '否'],
                        }, function(index){
                            console.log(data1);
                            $.ajax({
                                url:'/user/transfer/teacher',
                                data:data1,
                                type:'POST',
                                dataType:'json',
                                success:function(res){
                                    layer.alert(res.message);
                                    if(res.code == 0){
                                        $("#myModal").modal('hide');
                                    }
                                }
                            });
                            layer.close(index);
                            return true;
                        }, function(index){
                            layer.close(index);
                        });
                    }else{
                        layer.alert(res.message);
                    }
                }
            });
        }
    </script>
@endsection